﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using DevExpress.XtraReports.UI;

namespace BHair.kucunpandian
{
    public partial class frmkcpdreprot : Form
    {
        public frmkcpdreprot()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void button1_Click(object sender, EventArgs e)
        {
            timeselect();
        }
        #region 按时间查询
        public DataSet timeselect()
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            string sql = string.Format("SELECT [id],[spid],[spname],[spkc],[pdkc],[pdyg],[pdtime],[pdID] FROM [BHairDB].[dbo].[kcpd] where pdtime>='{0}' and pdtime<='{1}'",dtpbegin.Text,dtpend.Text);
            string sql1= string.Format("SELECT [spid] as 商品编号,[spname] as 商品名称,[spkc] as 原始库存,[pdkc] as 盘点库存,[pdyg] as 盘点人,[pdtime] as 盘点日期,[pdID] as 盘点单号 FROM [BHairDB].[dbo].[kcpd] where pdtime>='{0}' and pdtime<='{1}'", dtpbegin.Text, dtpend.Text);
            SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
            SqlDataAdapter sda1 = new SqlDataAdapter(sql1,conn);
            DataSet ds = new DataSet();
            sda.Fill(ds, "kcpd");
            DataTable dt = new DataTable();
            sda1.Fill(dt);
            dataGridView1.DataSource = dt;
            return ds;
        }
        #endregion

        private void button2_Click(object sender, EventArgs e)
        {
            DevExpress.XtraReports.UI.XtraReport xr = new DevExpress.XtraReports.UI.XtraReport();
            xr.LoadLayout(AppDomain.CurrentDomain.BaseDirectory + @"bb\Reportkcpdbb.repx");
            xr.DataSource = timeselect();
            xr.ShowPreview();
        }
    }
}
